home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / lang / HeliOS3.lha / helios_demo_disk3 / source / Demo1_SinglePF.src < prev    next >
Encoding:
Text File  |  1995-11-11  |  11.6 KB  |  428 lines

  1.  
  2.   \ ***********************************************************
  3.   \
  4.   \                  SINGLE PLAYFIELD DEMO
  5.   \
  6.   \ ***********************************************************
  7.   \
  8.   \ This code demonstrates how to create a simple HeliOS single
  9.   \ playfield display.
  10.   \
  11.   \ An IFF file is then loaded and displayed.
  12.   \
  13.   \ This code is then expanded in the following Demos:
  14.   \
  15.   \ Demo2_SinglePFCopper.src
  16.   \ Demo3_SimpleSprite.src
  17.   \ Demo4_MultiSprites.src
  18.   \ Demo5_MultiSptCollide.src
  19.   \ Demo6_SimpleAnim.src
  20.   \ Demo7_MultiAnim.src
  21.   \
  22.   \ ***********************************************************
  23.  
  24.  
  25.   \ ***********************************************************
  26.   \ Re-initialise HeliOS dictionary to standard CORE vocabulary
  27.   \ ***********************************************************
  28.  
  29.   \ This should always be used at the start of any program which
  30.   \ is to be repeatedly recompiled.
  31.  
  32.   FORGET **CORE**
  33.  
  34.   \ *************************
  35.   \ Load include symbol files
  36.   \ *************************
  37.   \
  38.   \ These "include files" are pre-compiled (for speed) versions of the
  39.   \ Amiga includes and the Helios system includes.
  40.   \
  41.   \ Uncomment the lines below for standalone compilation, but otherwise
  42.   \ it is better to set these include files from the Helios Forth menus
  43.  
  44.   AMIGAINCLUDE HeliOS:HeliOS_AmigaInclude
  45.   USERINCLUDE  HeliOS:HeliOS_UserInclude
  46.  
  47.   \ ****************************************
  48.   \ Create display imagery file name strings
  49.   \ ****************************************
  50.  
  51.   \ These files are ordinary IFF's (and may be "PowerPacked" if required)
  52.   \
  53.   \ The pictures here will be loaded into each of the display BitMaps.
  54.   \
  55.  
  56.   $CONSTANTL Slice1Pic $Helios:Source/Data/Pic2$
  57.  
  58.   \ **************************************
  59.   \ Create display configuration constants
  60.   \ **************************************
  61.   \
  62.   \ Collect all "display-specific" parameters here and generate "named"
  63.   \ constants which make references easier than using numeric values.
  64.   \
  65.   \ Collecting these together here makes it easier to adjust things at any
  66.   \ time without having to search source code to replace values individually.
  67.   \
  68.  
  69.  
  70.   256                      CONSTANT DisplayHeight      \ Full PAL display
  71.   320                      CONSTANT DisplayWidth       \ Lores display
  72.   44                       CONSTANT DisplayTopLine     \ Display start
  73.  
  74.   DisplayWidth             CONSTANT Slice1Width        \ Lores width
  75.   DisplayWidth 32 +        CONSTANT Slice1RasterWidth  \ Raster=SWidth+32
  76.   DisplayHeight            CONSTANT Slice1Height       \ Slice height
  77.   DisplayHeight 32 +       CONSTANT Slice1RasterHeight \ Slice Raster=DHgt+32
  78.   0                        CONSTANT Slice1Mode         \ Lores
  79.   3                        CONSTANT Slice1Planes       \ Slice bitplanes
  80.  
  81.   \ The calculation below takes the number of bitplanes and calculates
  82.   \ how many colours this represents.
  83.   \
  84.   \ One bitplane gives two colours.
  85.   \
  86.   \ Each additional bitplane multiplies the number of colours by two.
  87.   \
  88.   \ Performing a single LSL operation on any number multipies by 2, so we
  89.   \ have a quick method of multiplying by two for our colour calculation.
  90.   \
  91.   \ In this case, we need "2 to the power 3", which is 2*2*2=8.
  92.   \
  93.   \ e.g.                              2*2*2
  94.   \                                   ^ ^ ^
  95.   \                                   Total number of planes = 3
  96.   \
  97.   \
  98.   \ So, we take the first value two
  99.   \
  100.   \ e.g.                              2*2*2
  101.   \                                   ^
  102.   \                                  Initial start value of 2
  103.   \
  104.   \ and we now need to multiply it by two "the_number_of_planes minus_one"
  105.   \ more times.
  106.   \
  107.   \ e.g.                              2*2*2
  108.   \                                     ^ ^
  109.   \                                     Total planes minus one
  110.   \
  111.   \
  112.   \ So, Number of colours = 2 operated on by LSL NumberOfPlanes-1 times.
  113.   \
  114.  
  115.   2 Slice1Planes 1- LSL    CONSTANT Slice1Colours      \ A-slice colours
  116.  
  117.   \ ***********************
  118.   \ Error handling routines
  119.   \ ***********************
  120.  
  121.   \ This error handler allows all errors to be routed via a comprehensive
  122.   \ sequential closedown routine, which is associated with the HeliOS
  123.   \ system error handler word ERROR".
  124.   \
  125.   \ When ERROR" senses an error, it prints an associated error message
  126.   \ delimited by '"' characters, and then closes everything down using the
  127.   \ routine CLOSEDOWN below which you have supplied.
  128.   \
  129.   \ This simplifies errors checks to the use of a single word, ERROR", which
  130.   \ displays a text message and closes eveything down.
  131.   \
  132.  
  133.   0 VARIABLE (CLOSEDOWN)
  134.  
  135.   : ?CLOSEDOWNERROR
  136.  
  137.   IF
  138.     CR
  139.     CR
  140.     TYPE
  141.     CR
  142.     CR
  143.     ." Press <Space> to quit!"
  144.     CR
  145.     CR
  146.     WAITSPACE
  147.     (CLOSEDOWN) @EXECUTE
  148.     QUIT
  149.   ELSE
  150.     DDROP
  151.   THEN
  152.   ;
  153.  
  154.   LATESTCFA VARIABLE ERROR1
  155.  
  156.   \ ****************************************
  157.   \ Create display pointer storage variables
  158.   \ ****************************************
  159.  
  160.   \ Here we create a set of "pointers", initially set to a "null" value.
  161.   \
  162.   \ These "pointers" are set up as "long addresses" when various components
  163.   \ of the display system are allocated and initialised.
  164.   \
  165.   \ Note that initially these are all set to zero, and we clear them back
  166.   \ to zero when we de-allocate the associated resource.
  167.   \
  168.   \ These DPOINTERs are all initially set to "null" by using '0.'.
  169.   \
  170.   \ When we allocate memory or Amiga system resources in the program at
  171.   \ run-time, these pointers are updated to contain the 32-bit address
  172.   \ of the newly allocated resource.
  173.   \
  174.   \ Subsequently the symbolic DPOINTER name can be used in your code to
  175.   \ represent the associated address.
  176.  
  177.   0. DPOINTER Display1             \ Main Display structure pointer
  178.   0. DPOINTER Slice1               \ Slice 1 Slice structure pointer
  179.  
  180.   0. DPOINTER Slice1_ColorMap      \ Slice 1 ColourMap structure pointer
  181.  
  182.   0. DPOINTER Slice1_RasInfo       \ Slice 1 RasInfo structure pointer
  183.  
  184.   0. DPOINTER Slice1_BMap          \ Slice 1 BitMap structure pointer
  185.  
  186.   0. DPOINTER Slice1_SliceControl  \ Slice 1 SliceControl structure pointer
  187.  
  188.   \ *************
  189.   \ Colour tables
  190.   \ *************
  191.  
  192.   \ Each colour entry requies 2 bytes of storage space
  193.  
  194.   CREATEL Slice1_ColorTable        \ Create longword pointer to table
  195.   Slice1Colours 2* 0 ALLOTFILL     \ Allocate Slice1 colours * 2 bytes
  196.  
  197.   \ ***********************************
  198.   \ Create Display and Slice structures
  199.   \ ***********************************
  200.  
  201.   \ This routine simply makes blank structures, which then need to be
  202.   \ initialised later (in the CREATE_DISPLAY routine).
  203.  
  204.   : CREATE_DSLICES
  205.  
  206.   DS_SIZEOF MAKESTRUCTURE Display1 MAKEPOINTER  \ Main "Display" structure
  207.  
  208.   SL_SIZEOF MAKESTRUCTURE Slice1   MAKEPOINTER  \ Display "Slice" structure
  209.   ;
  210.  
  211.   : FREE_DSLICES
  212.  
  213.   Slice1    DDUP FREEMEMORY   CLEARPOINTER
  214.   Display1  DDUP FREEMEMORY   CLEARPOINTER
  215.   ;
  216.  
  217.   \ ******************************
  218.   \ Create RasInfo structures etc.
  219.   \ ******************************
  220.  
  221.   : CREATE_RASINFO
  222.  
  223.   \ First allocate and initialise complete RasInfo structures.
  224.   \
  225.   \ This routine automatically allocates all BitMaps etc.
  226.   \
  227.  
  228.   Slice1RasterWidth Slice1RasterHeight Slice1Planes  OPENRASINFO
  229.   DFLAG0= ERROR" Fail: RasInfo1"
  230.   Slice1_RasInfo MAKEPOINTER
  231.  
  232.   \ Set invisible area "sprite margins" for slice RasInfo
  233.  
  234.   16              Slice1_RasInfo         ri_RxOffset    INDEX!L
  235.   16              Slice1_RasInfo         ri_RyOffset    INDEX!L
  236.  
  237.   \ Store BitMap pointer - often useful for later reference
  238.  
  239.   Slice1_RasInfo  ri_BitMap INDEXD@L Slice1_BMap MAKEPOINTER
  240.   ;
  241.  
  242.   : FREE_RASINFO
  243.  
  244.   Slice1_RasInfo   DDUP CLOSERASINFO   CLEARPOINTER
  245.   ;
  246.  
  247.   \ ********************************
  248.   \ Create Display/Slice Copperlists
  249.   \ ********************************
  250.  
  251.   \ This function builds the main display copperlist by:
  252.   \
  253.   \ 1. Initialising the Slice data structure
  254.   \ 2. Calling MAKECOPSTRIP for the slice, to build a copperlist
  255.   \ 3. Calling MAKEDISPLAY to build the master Display copperlist
  256.   \
  257.  
  258.   : CREATE_DISPLAY
  259.  
  260.   \ First initialise main display structures
  261.  
  262.   Slice1                           Display1  DS_Slice     INDEXD!L
  263.  
  264.   Slice1Width                      Slice1    SL_DWidth    INDEX!L
  265.   Slice1Height                     Slice1    SL_DHeight   INDEX!L
  266.   DisplayTopLine                   Slice1    SL_DyOffset  INDEX!L
  267.   Slice1_RasInfo                   Slice1    SL_RasInfo   INDEXD!L
  268.   Slice1_ColorMap                  Slice1    SL_ColorMap  INDEXD!L
  269.   Slice1Mode                       Slice1    SL_Modes     INDEX!L
  270.  
  271.   \ Generate copper list information for each of the display slices
  272.  
  273.   Slice1 MAKECOPSTRIP
  274.   D0= ERROR" Fail: Slice1CopStrip"
  275.  
  276.   \ Make display
  277.  
  278.   Display1 MAKEDISPLAY
  279.   D0= ERROR" Fail: Display1"
  280.   ;
  281.  
  282.   : FREE_DISPLAY
  283.  
  284.   Display1                 FREEDISPLAY
  285.   Slice1                   FREECOPSTRIP
  286.   ;
  287.  
  288.   \ ********************************************************
  289.   \ Create SliceControl structures for double buffered slice
  290.   \ ********************************************************
  291.  
  292.   \ SliceControl structures are used to control any slices which perform
  293.   \ mapping or scrolling functions, or which require double or triple
  294.   \ playfield buffering.
  295.   \
  296.   \ In this case we have one slice which does not scroll, is not mapped,
  297.   \ but IS double buffered.
  298.   \
  299.  
  300.   : CREATE_SLICECONTROL
  301.  
  302.   \ Make SliceControl for double buffered bitmap display
  303.  
  304.   Slice1  0 0 MAKESLICECONTROL
  305.   DFLAG0= ERROR" Fail: SliceControl1"
  306.   Slice1_SliceControl MAKEPOINTER
  307.  
  308.   \ Install slice controls into HeliOS display control system
  309.  
  310.   Slice1_SliceControl  INSTALLSLICECONTROL
  311.   ;
  312.  
  313.   : FREE_SLICECONTROL
  314.  
  315.   CLEARSLICECONTROLS
  316.   Slice1_SliceControl  CLOSESLICECONTROL
  317.   ;
  318.  
  319.   \ These routines load an IFF picture into supplied BitMap, and correctly
  320.   \ initialises the supplied ColorTable.
  321.   \
  322.   \ The ColorTable is then used to create an initialised ColorMap structure.
  323.   \
  324.  
  325.   : CREATE_IMAGERY
  326.  
  327.   Slice1_BMap
  328.   Slice1_ColorTable
  329.   Slice1Pic
  330.   10 2 DOSLIB                        \ Call to internal HeliOS library
  331.   10 <> ERROR" Fail: Slice1Pic"
  332.  
  333.   Slice1_ColorTable  Slice1Colours MAKECOLORMAP  \ Allocate ColourMap
  334.   DFLAG0= ERROR" Fail: Slice1ColorMap"
  335.   Slice1_ColorMap MAKEPOINTER
  336.   ;
  337.  
  338.   : FREE_IMAGERY
  339.  
  340.   Slice1_ColorMap  DDUP FREECOLORMAP  CLEARPOINTER
  341.   ;
  342.  
  343.   \ *********************
  344.   \ Close down everything
  345.   \ *********************
  346.  
  347.   : CLOSEDOWN
  348.  
  349.   FREE_SLICECONTROL
  350.   FREE_DISPLAY
  351.   FREE_IMAGERY
  352.   FREE_RASINFO
  353.   FREE_DSLICES
  354.   RESETERROR"
  355.   ;
  356.  
  357.   LATESTCFA (CLOSEDOWN) !
  358.  
  359.   : TestDisplay          \ Start of program
  360.  
  361.   SCRCLR
  362.  
  363.   CR
  364.   ."        **********************************************************"
  365.   CR 6 FPENSET
  366.   ."                          SINGLE PLAYFIELD DEMO"
  367.   CR 1 FPENSET
  368.   ."        **********************************************************"
  369.   CR
  370.   CR
  371.   ."        This code demonstrates how to create a simple HeliOS single"
  372.   CR
  373.   ."        playfield display."
  374.   CR
  375.   CR
  376.   ."        An IFF file is then loaded and displayed."
  377.   CR
  378.   CR
  379.   ."        This code is then expanded in the following Demos:"
  380.   CR
  381.   CR
  382.   ."        Demo2_SinglePFCopper.src"
  383.   CR
  384.   ."        Demo3_SimpleSprite.src"
  385.   CR
  386.   ."        Demo4_MultiSprites.src"
  387.   CR
  388.   ."        Demo5_MultiSptCollide.src"
  389.   CR
  390.   ."        Demo6_SimpleAnim.src"
  391.   CR
  392.   ."        Demo7_MultiAnim.src"
  393.   CR
  394.   CR
  395.   ."        **********************************************************"
  396.   CR 6 FPENSET
  397.   ."                  Press <Space> or <L-Mouse> to see Demo          "
  398.   CR 1 FPENSET
  399.   ."        **********************************************************"
  400.   CR
  401.  
  402.   WAITSPACE
  403.  
  404.   SCRCLR
  405.  
  406.   ERROR1 SETERROR"       \ Redirect system errors to our routine ERROR1
  407.  
  408.   CREATE_DSLICES
  409.   CREATE_RASINFO
  410.   CREATE_IMAGERY
  411.   CREATE_DISPLAY
  412.   CREATE_SLICECONTROL
  413.  
  414.   HeliOS_On
  415.  
  416.   1 FrameRate !L
  417.  
  418.   Display1 SHOWDISPLAY
  419.  
  420.   WAITSPACE
  421.  
  422.   HeliOS_Off
  423.  
  424.   CLOSEDOWN
  425.   ;
  426.  
  427.   TestDisplay
  428.